package com.asiainfo.kbisheet.components.condition.month
{
	import com.asiainfo.kbisheet.components.condition.ConditionInput;
	import com.asiainfo.kbisheet.components.condition.ConditionItem;
	
	import mx.controls.Alert;
	import mx.controls.DateField;
	import mx.formatters.DateFormatter;

	/**
	 * 月(month)输入条件的单组件呈现。
	 * <p>云南PSO最初的配置字符串为mdate。</p>
	 */
	public class ConditionInputMonth extends ConditionInput
	{
		private var dateField:DateField;
		private var dateFormat:DateFormatter;
		
		public function ConditionInputMonth(parent:ConditionItem)
		{
			super(parent);
		}
		
		override public function get value():String{			
			if(dateField.selectedDate != null){				
				return dateFormat.format(dateField.selectedDate);
			}
			else{
				return null;
			}
		}
		
		/**
		 * 设置日期的可选范围
		 */
		public function set selectableRange(value:Object):void{
			dateField.selectableRange = value;	
			dateField.selectedDate = value.rangeEnd;
		}
		
		override protected function createChildren():void {
			dateField = new DateField();
			dateField.yearNavigationEnabled = true;
			/*使用隐藏的日期和固定的宽度，避免选择日期后出现的null值。*/
			dateField.formatString = "YYYY年MM月      DD";
			dateField.width = 99;
			addElement(dateField);
			
			dateFormat = new DateFormatter();
			dateFormat.formatString="YYYYMM";
		}
	}
}